/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boxin.ims.modules.wechat.dao.WXPayDao;
import com.boxin.ims.modules.wechat.entity.WXPay;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;

/**
 * 微信支付Service
 * @author 肖乾
 * @version 2014-11-12
 */
@Component
@Transactional(readOnly = true)
public class WXPayService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(WXPayService.class);
	
	@Autowired
	private WXPayDao wXPayDao;
	
	public WXPay get(Long id) {
		return wXPayDao.findOne(id);
	}
	
	public Page<WXPay> find(Page<WXPay> page, WXPay wXPay) {
		DetachedCriteria dc = wXPayDao.createDetachedCriteria();
		if (wXPay.getUser()!=null && wXPay.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", wXPay.getUser().getId()));
		}
		if (StringUtils.isNotEmpty(wXPay.getName())){
			dc.add(Restrictions.like("name", "%"+wXPay.getName()+"%"));
		}
		dc.addOrder(Order.desc("id"));
		return wXPayDao.find(page, dc);
	}
	
	/**
	 * 绑定微信信息
	 *@author xiaoqian
	 * @param userId
	 * @return
	 * 2014-11-12下午8:03:39
	 */
	public WXPay getByUserId(Long userId){
		return wXPayDao.getByUserId(userId);
	}
	
	@Transactional(readOnly = false)
	public void save(WXPay wXPay) {
		wXPayDao.save(wXPay);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		wXPayDao.deleteById(id);
	}
	
}
